package com.zjt.myjiakao.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;

import com.zjt.myjiakao.R;

import java.util.ArrayList;
import java.util.List;


public class ImgDialog extends Dialog {
    public ImgDialog(Context context) {
        super(context, R.style.dialog_no_anim);
    }

    public static ImgDialog show(Context context, String url) {
        List<String> list = new ArrayList<>();
        list.add(url);
        return show(context, list);
    }

    public static ImgDialog show(Context context, List<String> imgs) {
        return show(context, imgs, 0);
    }

    public static ImgDialog show(Context context, List<String> imgs, int position) {
        final ImgDialog dialog = new ImgDialog(context);
        View view = View.inflate(context, R.layout.img_dialog, null);
        ViewPager viewPager = view.findViewById(R.id.viewpager);
        viewPager.setAdapter(new ImgPagerAdapter(context, imgs, dialog));
        viewPager.setCurrentItem(position);
        dialog.setContentView(view);
        WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = manager.getDefaultDisplay();
        WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
        params.width = display.getWidth();
        params.height = display.getHeight();
        params.gravity = Gravity.CENTER;
        dialog.getWindow().setAttributes(params);
        dialog.show();
        return dialog;
    }

}
